import request from '@/utils/request';

export function getCaptainQueryList() {
    return request({
        url: '/v1/head/queryList',
        method: 'get'
    });
}

export function getActivityList({ pageNum, pageSize, categoryId, supplierId, status, nameOrCode }) {
    return request({
        url: '/v1/goods/sale/activity/list',
        method: 'post',
        data: {
            categoryId: !!categoryId ? categoryId : undefined,
            supplierId: !!supplierId ? supplierId : undefined,
            nameOrCode: !!nameOrCode ? nameOrCode : undefined,
            pageNum,
            pageSize,
            status
        }
    });
}

export function getActivityDetail(activityId) {
    return request({
        url: `/v1/goods/sale/activity/detail/${activityId}`,
        method: 'get'
    });
}

export function stopActivity(activityId) {
    return request({
        url: `/v1/goods/sale/activity/update/${activityId}/finished`,
        method: 'post'
    });
}

export function editActivity({
    id,
    goodsId,
    goodsSkuId,
    times,
    startTime,
    endTime,
    limitOrderCount,
    takeGoodsDays,
    totalGoodsCount,
    preSalesCount = 0,
    preHitCount = 0
}) {
    return request({
        url: '/v1/goods/sale/activity/update',
        method: 'post',
        data: {
            id,
            startTime: times[0],
            endTime: times[1],
            limitOrderCount,
            takeGoodsDays,
            totalGoodsCount,
            preSalesCount,
            preHitCount
        }
    });
}

export function addSaling({
    goodsId,
    goodsSkuId,
    times,
    startTime,
    endTime,
    limitOrderCount,
    takeGoodsDays,
    totalGoodsCount
}) {
    return request({
        url: '/v1/goods/sale/activity/create',
        method: 'post',
        data: {
            startTime: times[0],
            endTime: times[1],
            goodsId,
            goodsSkuId,
            limitOrderCount,
            takeGoodsDays,
            totalGoodsCount
        }
    });
}
